<template>
	<view :class="[primarySize()]">
		<view class="container">
			<view class="p30">
				<view class="post_item" v-for="(job,index) in jobs">
					<view class="flex-box">
						<view class="fwb fs36 col3 m-ellipsis pr15 maxw60">{{job.message_text.name}}</view>
						<view class="urgent" v-if="job.message_text.in_hurry">急聘</view>
						<view class="flex-grow-1 tr fs32 fwb col4">{{job.message_text.salary_text}}</view>
					</view>
					<view class="mt15 col6 fs24">{{job.message_text.company_name}}</view>
					<view class="clearfix pt10">
						<view class="tips_item">{{job.message_text.work_experience}}</view>
						<view class="tips_item">{{job.message_text.education_level}}</view>
						<view class="tips_item" v-for="benefit in job.message_text.benefits">{{benefit.name}}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {

				receive_user_id:0,
				show:true,
				jobs: [],
				showPromoteTip: false,
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.primaryColor()
			})
		},
		/**
		* 生命周期函数--监听页面加载
		*/
		onLoad: function (options) {

		    this.receive_user_id = options.receive_user_id;
		    this.refresh();
		},
		methods: {
			refresh() {
			    this.jobs = [];
				this.$core.get({
			      url: '/xilujob.job/chat_job_lists', data: {receive_user_id:this.receive_user_id}, success: ret => {
			        this.jobs = ret.data;
			        // 检查是否有职位数据
			        if (!this.jobs || this.jobs.length === 0) {
			          this.showNoJobsAlert();
			        }
			      }
			    });
			},
			// 显示无职位提示
			showNoJobsAlert() {
				uni.showModal({
					title: '提示',
					content: '发送失败，您还未发布招聘信息',
					showCancel: false,
					success: (res) => {
						if (res.confirm) {
							// 第一次点击确定后，显示第二个提示
							this.showPublishConfirm();
						}
					}
				});
			},
			// 显示前往发布职位确认
			showPublishConfirm() {
				uni.showModal({
					title: '提示',
					content: '前往发布职位',
					success: (res) => {
						if (res.confirm) {
							// 点击确定跳转到发布职位页面
							uni.navigateTo({
								url: '/pages/company/publish_full'
							});
						} else {
							// 点击取消返回上一页
							uni.navigateBack();
						}
					}
				});
			},
			bindSendJob(e){
				let jobId = e.currentTarget.dataset.id;
				chatIM.sendMessage(this.data.receive_user_id, jobId,3);
				wx.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
.post {
		&_list {
			padding-top: 10rpx;
		}

		&_item {
			width: 690rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(0, 0, 0, 0.03);
			border-radius: 18rpx;
			margin-top: 20rpx;
			padding: 30rpx;

			.maxw60 {
				max-width: 60%;
			}

			.urgent {
				width: 74rpx;
				height: 37rpx;
				line-height: 33rpx;
				text-align: center;
				font-size: 24rpx;
				color: #FF7B20;
				border-radius: 6rpx;
				border: 2rpx solid #FF7B20;
			}

			.tips_item {
				height: 32rpx;
				background: #ECEFF5;
				border-radius: 4rpx;
				font-weight: 400;
				font-size: 22rpx;
				color: #A5A5A5;
				line-height: 32rpx;
				display: inline-block;
				vertical-align: top;
				margin-right: 10rpx;
				margin-top: 10rpx;
				padding: 0 8rpx;
			}

			.cover {
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
			}
		}
	}
</style>
